/**
 * $Revision: 1.0 $
 * $Author: Geln Yang $
 * $Date: Jun 24, 2009 9:33:09 AM $
 *
 * Author: Eric Yang
 * Date  : Jun 24, 2009 9:33:09 AM
 *
 */
package c4j.cvs.patch;

import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import c4j.cvs.patch.CVSRecord;
import c4j.cvs.patch.Patcher;
import c4j.file.FileUtils;

/**
 * @author Eric Yang
 * @version 1.0
 */
public class TestFBPatcher {

	public static void main(String[] args) throws IOException {
		String cvsReportFilePath = "d:\\cvsreport.csv";
		//testList(cvsReportFilePath);
		testPatch(cvsReportFilePath);
		//testUpdateList();
		System.out.println("OVER");
	}

	public static void testUpdateList() throws IOException {
		String cvsReportFilePath = "d:\\cvsreport.csv";
		List<CVSRecord> records = Patcher.listModifiedFiles(cvsReportFilePath);
		Set<String> recordSet = new HashSet<String>();
		for (int i = 0; i < records.size(); i++) {
			recordSet.add(records.get(i).getFilePath());
		}
		cvsReportFilePath = "d:\\cvsreport_new.csv";

		List<CVSRecord> newRecords = Patcher.listModifiedFiles(cvsReportFilePath);

		for (int i = 0; i < newRecords.size(); i++) {
			String filepath = newRecords.get(i).getFilePath();
			if (!recordSet.contains(filepath)) {
				System.out.println(filepath);
			}
		}
	}

	public static void testList(String cvsReportFilePath) throws IOException {
		List<CVSRecord> records = Patcher.listModifiedFiles(cvsReportFilePath);
		for (int i = 0; i < records.size(); i++) {
			System.out.println(records.get(i).getFilePath());
		}
	}

	public static void testPatch(String cvsReportFilePath) throws IOException {
		Map<String, String> parameters = new HashMap<String, String>();
		parameters.put(Patcher.JAVA_COMPILE_DIR, "D:\\Project Code\\FB-2008-01-23-SWIFT\\build\\build\\classes\\");

		parameters.put(Patcher.JAVA_DIR_1,
				"C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\\swfund\\WEB-INF\\classes\\");
		parameters.put(Patcher.CONF_DIR_1,
				"C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\\swfund\\WEB-INF\\classes\\");
		parameters.put(Patcher.PROP_DIR_1,
				"C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\\swfund\\WEB-INF\\classes\\");

		parameters.put(Patcher.JSP_DIR, "C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\\swfund\\");

		parameters.put(Patcher.JAVA_DIR_2, "C:\\swfund_daemon\\lib\\swfund_daemon.jar\\");
		parameters.put(Patcher.CONF_DIR_2, "C:\\swfund_daemon\\conf\\");
		parameters.put(Patcher.PROP_DIR_2, "C:\\swfund_daemon\\lib\\swfund_daemon.jar\\");

		Patcher.patch(cvsReportFilePath, FileUtils.getTodayStoreDir("D:\\FB_PATCH"), parameters);
	}
}
